package spindles.api.domain;

import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.SecondaryKey;

@Entity
public class Person extends DomainObject{
	
	/**
	 * 
	 */
	private static transient final long serialVersionUID = -7454331589728007206L;

	@SecondaryKey(relate=MANY_TO_ONE)
	private String firstName;
	
	@SecondaryKey(relate=MANY_TO_ONE)
	private String lastName;	
	
	private String comments;

	public Person(String firstName, String lastName, String comments) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.comments = comments;
	}
	
	public Person(){
		super();
	}	
	
	/**
	 * A person is equal to another when they have the same name and lastname
	 */
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj, false, Person.class,
				new String[] {"comments"});
	}
	
	public int hashCode() {		
		return HashCodeBuilder.reflectionHashCode(17, 
				37, this, false, Person.class, new String[] {"comments"});	
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public String getName(){
		return getLastName() + "  " + getFirstName();
	}

}
